package vis;

import java.awt.Graphics2D;
import java.util.List;
import java.util.Vector;

public class Scene {
	private List<Drawable> objects = new Vector<Drawable>();
	
	private List<GLine> lines = new Vector<GLine>();
	private List<GPoint> points = new Vector<GPoint>();
	private List<Drawable> others = new Vector<Drawable>();
	
	private List<Viewport> vports = new Vector<Viewport>();
	
	public Scene()
	{
		
	}
	
	public void reset()
	{
		objects.clear();
		lines.clear();
		points.clear();
		others.clear();
		repaintViewports();
	}
	
	public void addObject(Drawable d)
	{
		if(objects.contains(d)) return;
		objects.add(d);
		if(d instanceof GLine)
		{
			lines.add((GLine) d);
			addObject((Drawable) ((GLine)d).getP1());
			addObject((Drawable) ((GLine)d).getP2());
		}
		if(d instanceof GPoint)
			points.add((GPoint) d);
		else
			others.add(d);
	}
	
	protected void signalChange()
	{
		repaintViewports();
	}
	
	private void repaintViewports()
	{
		for(Viewport v : vports)
			v.repaint();
	}
	
	public void render(Graphics2D g)
	{
		for(Drawable o : others)
			if(o.isVisible())
				o.draw(g);
		for(GLine l : lines)
			if(l.isVisible())
				l.draw(g);
		for(GPoint p : points)
			if(p.isVisible())
				p.draw(g);
	}
}
